package com.bnlr.lrparking.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bnlr.lrparking.R;
import com.bnlr.lrparking.model.TopUpM;
import com.yolanda.nohttp.rest.Request;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by rr on 2016/7/2.
 */
public class RetentionMoneyAdapter extends BaseAdapter {

    public Request<String> mRequest;
    private Context mcontext;
    private List<TopUpM.DataBean> list=new ArrayList<>();
    private LayoutInflater inflater;
    private int defaultSelection = -1;


    public RetentionMoneyAdapter(Context context, List<TopUpM.DataBean> list) {
        super();
        this.mcontext = context;
        this.list = list;
        inflater = LayoutInflater.from(mcontext);
    }

    @Override
    public int getCount() {
        if (list != null) {
            return list.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        final ViewHoder hoder;
        if (convertView == null) {
            hoder = new ViewHoder();
            convertView = inflater.inflate(R.layout.item_retentionmoney, null);
            hoder.tv_topup_share = (TextView) convertView.findViewById(R.id.tv_topup_share);
            hoder.tv_topup_share1 = (TextView) convertView.findViewById(R.id.tv_topup_share1);
            hoder.rely_topup=(RelativeLayout)convertView.findViewById(R.id.rely_topup);
            convertView.setTag(hoder);
        } else {
            hoder = (ViewHoder) convertView.getTag();
        }
        final TopUpM.DataBean bean = list.get(i);
        hoder.tv_topup_share.setText(bean.getShareValue()+"");
        if (i == defaultSelection) {// 选中时设置单纯颜色
            hoder.tv_topup_share.setTextColor(mcontext.getResources().getColor(R.color.write));
            hoder.tv_topup_share1.setTextColor(mcontext.getResources().getColor(R.color.write));
            hoder.rely_topup.setBackgroundResource(R.mipmap.pay_moneybg_click);

        } else {// 未选中时设置selector
            hoder.tv_topup_share.setTextColor(mcontext.getResources().getColor(R.color.text_color));
            hoder.tv_topup_share1.setTextColor(mcontext.getResources().getColor(R.color.text_color));
            hoder.rely_topup.setBackgroundResource(R.mipmap.pay_moneybg_nor);
        }
        return convertView;
    }

    class ViewHoder {
        TextView tv_topup_share,tv_topup_share1;
        //
        RelativeLayout rely_topup;
    }

    public void setSelectPosition(int i) {
        this.defaultSelection = i;
    }
}
